<%@ Page Language="VB" MasterPageFile="~/Default.master" AutoEventWireup="false" CodeFile="Answers.aspx.vb" Inherits="Poll_Answers" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <div id="body">
        <div class="fullwidth">
            <table cellspacing="0" cellpadding="0" width="100%">
                <tr>
                    <td style="height: 16px">
                        <asp:HyperLink ID="AllPollCrumb" NavigateUrl="~/Poll/List.aspx" runat="server">All Polls</asp:HyperLink>
                        &raquo;
                        <asp:HyperLink ID="PollCrumb" runat="server" /></td>
                    <td align="right" style="height: 16px">
                        </td>
                </tr>
            </table>
        </div>
        <div class="fullwidth">
            <asp:Label ID="QuestionLabel" runat="server"></asp:Label>
            <br />
            <br />
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
                DataKeyNames="PollAnswerId" Width="100%" DataSourceID="SqlDataSource1" OnRowUpdating="GridView1_RowUpdating">
                <Columns>
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                    <asp:BoundField DataField="Answer" HeaderText="Answer" SortExpression="Answer" />
                    <asp:BoundField DataField="Rank" HeaderText="Rank" SortExpression="Rank" />
                </Columns>
            </asp:GridView>
            
        </div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ClubSiteDB %>"
            SelectCommand="SELECT [PollAnswerId], [QuestionId], [Answer], [Rank] FROM [PollAnswers] WHERE QuestionId = @pollId"
            DeleteCommand="DELETE FROM [PollAnswers] WHERE [PollAnswerId] = @original_PollAnswerId"
            InsertCommand="INSERT INTO [PollAnswers] ([PollAnswerId], [Answer], [QuestionId], [Rank]) VALUES (@pollAnswerId, @answer, @questionId, @rank)"
            OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [PollAnswers] SET [Answer] = @answer, [Rank] = @Rank WHERE [PollAnswerId] = @original_PollAnswerId">
            <SelectParameters>
                <asp:QueryStringParameter Name="pollId" QueryStringField="PollId" />
            </SelectParameters>
        </asp:SqlDataSource>
        <div class="fullwidth">
            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="PollAnswerId"
                    Height="50px" Width="100%" DataSourceID="SqlDataSource1" DefaultMode="Insert" OnItemInserting="DetailsView1_ItemInserting">
                    <Fields>
                        <asp:BoundField DataField="PollAnswerId" HeaderText="Answer" InsertVisible="False" ReadOnly="True"
                            SortExpression="PollAnswerId" />
                        <asp:TemplateField HeaderText="Answer" SortExpression="Answer">
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Answer") %>'></asp:TextBox>
                                <asp:RequiredFieldValidator ControlToValidate="TextBox1" ValidationGroup="Insert"
                                    ID="RequiredFieldValidator1" runat="server" ErrorMessage="Answer is required">*</asp:RequiredFieldValidator>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Rank" SortExpression="Rank">
                            <InsertItemTemplate>
                                <asp:TextBox ID="RankTextBox" runat="server" Text='<%# Bind("Rank") %>'></asp:TextBox>
                            </InsertItemTemplate>
                        </asp:TemplateField>
                        <asp:CommandField ValidationGroup="Insert" ShowInsertButton="True"
                            ShowCancelButton="False" InsertText="Add answer" />
                    </Fields>
                </asp:DetailsView>
        </div>
 </div>
</asp:Content>